//
//  ViewController.m
//  UI_liMap
//
//  Created by dllo on 15/8/9.
//  Copyright (c) 2015年 蒙奇D小路. All rights reserved.
//

#import "ViewController.h"
#import <MAMapKit/MAMapKit.h>
#import <AMapSearchKit/AMapSearchAPI.h>
#import "CustomAnnotationView.h"
#define APIKey  @"6e8ae216ead35d05dd571fd276544d34"

#define kDefaultLocationZoomLevel       16.1

/*
 
 MAMapView 主要属性
 
 中心经纬度坐标 结构体
 @property(nonatomic,assign)CLLocationCoordinate2D centerCoordinate;
 缩放级别
 @property(nonatomic,assign)CGFloat zoomLevel;
 罗盘位置
 @property(nonatomic,assign)CGPoint compassOrigin;
 比例尺位置
 @property(nonatomic,assign)CGPoint scaleOrigin;
 
 打开定位功能
 @property(nonatomic,assign)BOOL showsUserLocation;
 iOS 8以上系统需在info.plist添加字段
 若仅需在用户使用app时定位,添加字段NSLocationWhenInUseUsageDescription
 若在用户使用app时仍然需要定位,添加字段NSLocationAlwaysUsageDescription
 
 定位模式
 @property(nonatomic)MAUserTrackingMode userTrackingMode;
 三种模式
 MAUserTrackingModeNone
 MAUserTrackingModeFolow 跟随用户位置: 地图重点始终为用户所在位置
 MAUserTrackingModeFollowWithHeading 跟随用户位置和方向:地图中心店始终为用户所在位置,地图旋转方向跟随手机方向变化
 */

/*
 搜索POI接口
 - (void)AMapPlaceSearch:(AMapPlaceSearchRequest *)request;
 
 AMapPlaceSearchRequest关键属性 
 Search类型
 @property (nonatomic, assign) AMapSearchType searchType; // 默认为AMapSearchType_PlaceKeyword
 
 类型
 AMapSearchType_PlaceID 按POI ID搜索
 AMapSearchType_PlaceKeyword 按关键字搜索
 AMapSearchType_PlaceAround 按关键字进⾏行附近搜索
 AMapSearchType_PlacePolygon 按关键字进⾏行⾃自定义范围搜索
 
 AMapPlaceSearchRequest  用法 
 按POI ID搜索 AMapSearchType_PlaceID
 根据POI ID搜索,⼀一般是在使⽤用其他搜索⽅方式得到POI后,取POI ID做进⼀一步搜索,获取POI的详细信息
 搜索时,设置requireExtension为YES。
 按关键字搜索 AMapSearchType_PlaceKeyword
 需要设置以下参数
 @property (nonatomic, copy) NSString *keywords; // 查询关键字,多个关键字⽤用“|”分割,“空格"表⽰示与,“双引 号”表⽰示不可分割
 @property (nonatomic, strong) NSArray *city; // 城市数组,可选值:cityname(中⽂文或中⽂文全拼)、 citycode、adcode
 //若city为空,则返回结果在suggestion中,返回多个城市的poi数据 附近搜索 AMapSearchType_PlaceAround
 需要设置以下参数
 @property (nonatomic, copy) NSString *keywords; // 查询关键字,多个关键字⽤用“|”分割,“空格"表⽰示与,“双引 号”表⽰示不可分割
 @property (nonatomic, copy) AMapGeoPoint *location; // 中⼼心点坐标
 @property (nonatomic, assign) NSInteger radius; // 查询半径,单位:⽶米 [default = 3000]
 ⾃自定义范围搜索 AMapSearchType_PlacePolygon 需要设置以下参数
 @property (nonatomic, copy) NSString *keywords; // 查询关键字,多个关键字⽤用“|”分割,“空格"表⽰示与,“双引 号”表⽰示不可分割
 @property (nonatomic, copy) AMapGeoPolygon *polygon; //⾃自定义搜索范围
 */


@interface ViewController ()<MAMapViewDelegate, AMapSearchDelegate, UITableViewDataSource,UITableViewDelegate, UIGestureRecognizerDelegate>
{
    MAMapView *_mapView;
     UIButton *_locationButton;
    
    AMapSearchAPI * _search;
    
    //代表地理坐标精度和时间戳信息。
    CLLocation *_currentLocation;
    
    
    //显示搜索结果的tableView
    UITableView *_tableView;
    //记录POI对象数组
    NSArray *_pois;
    //存放annotation
    NSMutableArray *_annotations;
    //记录annotation是否被添加
    NSMutableArray *_isAddAnnotations;
    
    //声明长按手势
    UILongPressGestureRecognizer *_longPressGesture;
    
    //目的地标注
    MAPointAnnotation *_destinationPoint;
    
    //记录路线的数组
    NSArray *_pathPolyines ;


    
}

@end

@implementation ViewController



#pragma mark - 数据初始化
- (void)initAttributes
{
    
    _annotations = [NSMutableArray array];
    _pois = nil;
    
    // 初始化长按手势
    _longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPrss:)];
    _longPressGesture.delegate = self;
    [_mapView addGestureRecognizer:_longPressGesture];
}

#pragma mark - tableView初始化
-(void)initTableView
{
    CGFloat halfHeight = CGRectGetHeight(self.view.bounds) * 0.4;
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, halfHeight + 128,
                                                               CGRectGetWidth(self.view.bounds), halfHeight) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    //NSLog(@"%ld",(unsigned long)_pois.count);
    return _pois.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"行 = %ld",(long)indexPath.row);
    
    static NSString *cellIdentifier = @"cellIdentifier";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }
    
    AMapPOI *poi = _pois[indexPath.row];
    
    cell.textLabel.text = poi.name;
    cell.detailTextLabel.text = poi.address;
    
    return cell;
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //取消重复添加annotation
    NSString *tempStr =[NSString stringWithFormat:@"%ld",indexPath.row];
    if (![_isAddAnnotations containsObject:tempStr])
    {
        //取消点击cell阴影效果
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        AMapPOI *poi = [_pois objectAtIndex:indexPath.row];
        //为POI点创建标注并添加
        MAPointAnnotation *annotation = [[MAPointAnnotation alloc] init];
        //给坐标
        annotation.coordinate = CLLocationCoordinate2DMake(poi.location.latitude, poi.location.longitude);
        //给城市名
        annotation.title =poi.city;
        //给详细地址
        annotation.title =poi.address;
        //设置当前地图中心点
        [_mapView setCenterCoordinate:annotation.coordinate animated:YES];
        //把annotation 添加到 _annotations数组中
        [_annotations addObject:annotation];
        //把annotation 添加到 _mapView上
        [_mapView addAnnotation:annotation];
        [_isAddAnnotations addObject:tempStr];
    }
    
    
    ////  //取消点击cell阴影效果
    //    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //    AMapPOI *poi = [_pois objectAtIndex:indexPath.row];
    //    //为POI点创建标注并添加
    //    MAPointAnnotation *annotation = [[MAPointAnnotation alloc] init];
    //    //给坐标
    //    annotation.coordinate = CLLocationCoordinate2DMake(poi.location.latitude, poi.location.longitude);
    //
    //    //给城市名
    //    annotation.title =poi.city;
    //    //给详细地址
    //    annotation.title =poi.address;
    //
    //    //设置当前地图中心点
    //    [_mapView setCenterCoordinate:annotation.coordinate animated:YES];
    //    //把annotation 添加到 _annotations数组中
    //    [_annotations addObject:annotation];
    //    //把annotation 添加到 _mapView上
    //    [_mapView addAnnotation:annotation];
}




//search初始化 显示当前地址 逆地理编码 地理坐标->地址
-(void)initSearch
{
    _search= [[AMapSearchAPI alloc] initWithSearchKey:APIKey Delegate:self];
}


//控件初始化
-(void)initControls
{
    _locationButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _locationButton.frame = CGRectMake(20, CGRectGetHeight(_mapView.bounds) - 80, 40, 40);
    _locationButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
    UIViewAutoresizingFlexibleTopMargin;
    _locationButton.backgroundColor = [UIColor whiteColor];
    _locationButton.layer.cornerRadius = 5;
    [_locationButton addTarget:self action:@selector(locateAction)
              forControlEvents:UIControlEventTouchUpInside];
    [_locationButton setImage:[UIImage imageNamed:@"location_no"] forState:UIControlStateNormal];
    [_mapView addSubview:_locationButton];
    
    
    
    //添加搜索按钮
    UIButton *searchButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    searchButton.frame = CGRectMake(80, CGRectGetHeight(_mapView.bounds) - 80, 40, 40);
    searchButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
    UIViewAutoresizingFlexibleTopMargin;
    searchButton.backgroundColor = [UIColor whiteColor];
    [searchButton setImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
    [searchButton addTarget:self action:@selector(searchAction)
           forControlEvents:UIControlEventTouchUpInside];
    [_mapView addSubview:searchButton];
    
    
    //路线按钮
    UIButton *pathButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    pathButton.frame = CGRectMake(140, CGRectGetHeight(_mapView.bounds) - 80, 40, 40);
    pathButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
    pathButton.backgroundColor = [UIColor whiteColor];
    [pathButton setImage:[UIImage imageNamed:@"path"] forState:UIControlStateNormal];
    
    [pathButton addTarget:self action:@selector(pathAction) forControlEvents:UIControlEventTouchUpInside];
    
    [_mapView addSubview:pathButton];


    
    
    
}

#pragma mark - 搜索按钮功能实现searchAction
//搜索按钮功能实现searchAction
-(void)searchAction
{
    if(_currentLocation ==nil || _search ==nil)
    {
        NSLog(@"search failed");
        return;
    }
    AMapPlaceSearchRequest *request = [[AMapPlaceSearchRequest alloc] init];
    
    //按关键字进行附近搜索
    request.searchType = AMapSearchType_PlaceAround;
    //查询半径  单位:米
    request.radius = 5000;
    //设置搜索中心位置
    request.location = [AMapGeoPoint locationWithLatitude:_currentLocation.coordinate.latitude longitude:_currentLocation.coordinate.longitude];
    //搜索关键字
    request.keywords = @"KTV";
    [_search AMapPlaceSearch:request];
    
}


#pragma mark - 长按手势事件
-(void)handleLongPrss:(UILongPressGestureRecognizer *)gesture
{
    if (gesture.state == UIGestureRecognizerStateBegan)
    {
        
        //  //手势在当前view的坐标 ,就是可以获取到手指碰触屏幕的位置
        //        CGPoint p = [gesture locationInView:_mapView];
        //        NSLog(@"press on (%f,%f)",p.x,p.y);
        
        //将屏幕坐标转化为经纬度坐标
        CLLocationCoordinate2D coordinate = [_mapView convertPoint:[gesture locationInView:_mapView] toCoordinateFromView:_mapView];
        
        //添加目的地标注
        //如果目的地标注不为空, 就清空 ,还要清空路线
        if (_destinationPoint != nil)
        {
            
            
            //先从_mapView移除
            [_mapView removeAnnotation:_destinationPoint];
            //再清空
            _destinationPoint = nil;
            
//            //清空所有的覆盖物路线
//            [_mapView removeOverlays:_pathPolyines];
//            _pathPolyines = nil;
            
        }
        _destinationPoint = [[MAPointAnnotation alloc] init];
        _destinationPoint.coordinate = coordinate;
        _destinationPoint.title = @"Destination";
        
        [_mapView addAnnotation:_destinationPoint];

    }
    
}


#pragma mark - 路线按钮实现

-(void)pathAction
{
    //目的地,出发点,search 任意一个为空就返回return
    if(_destinationPoint ==nil || _currentLocation ==nil || _search ==nil)
    {
        NSLog(@" path search failed");
        
        return ;
    }
    
    //搜索路径的request
    AMapNavigationSearchRequest *request = [[AMapNavigationSearchRequest alloc] init];
    //设置为步行路径规划
    request.searchType  = AMapSearchType_NaviWalking;
    //出发点 ,
    request.origin = [AMapGeoPoint locationWithLatitude:_currentLocation.coordinate.latitude longitude:_currentLocation.coordinate.longitude];
    //目的地
    request.destination = [AMapGeoPoint locationWithLatitude:_destinationPoint.coordinate.latitude longitude:_destinationPoint.coordinate.longitude];
    
    //发起路线请求
    [_search AMapNavigationSearch:request];
}


- (void)locateAction
{
    if (_mapView.userTrackingMode != MAUserTrackingModeFollow)
    {
        //  三种模式
        //MAUserTrackingModeNone
        //MAUserTrackingModeFollow 跟随⽤用户位置:地图中⼼心点始终为⽤用户所在位置
        //MAUserTrackingModeFollowWithHeading 跟随⽤用户位置和⽅方向:地图中⼼心点始终为⽤用户所在位置,地图旋转⽅方向跟随 ⼿手机⽅方向变化
        [_mapView setUserTrackingMode:MAUserTrackingModeFollowWithHeading animated:YES];
        [_mapView setZoomLevel:kDefaultLocationZoomLevel animated:YES];
    } }


//MAMapView初始化方法
-(void)initMapView
{
    [MAMapServices sharedServices].apiKey =APIKey;
    _mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 64, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) * 0.5)];
    _mapView.delegate =self;
    //设置罗盘位置
    _mapView.compassOrigin =  CGPointMake(_mapView.compassOrigin.x, 22);
    //设置比例尺位置
    _mapView.scaleOrigin = CGPointMake(_mapView.scaleOrigin.x, 22);
    [self.view addSubview:_mapView];
    
    //打开定位
    _mapView.showsUserLocation = YES;
    

}

//改变按钮状态
-(void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated
{
    if (mode ==MAUserTrackingModeNone)
    {
        [_locationButton setImage:[UIImage imageNamed:@"location_no"] forState:UIControlStateNormal];
    }
    else
        if (mode ==MAUserTrackingModeFollow)
        {
            [_locationButton setImage:[UIImage imageNamed:@"location_yes"] forState:UIControlStateNormal];
        }
        else
        {
            [_locationButton setImage:[UIImage imageNamed:@"heart_red@2x.png"] forState:UIControlStateNormal];
        }
    
    
}


//获取当前用户经纬度的回调方法
-(void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation
{
    NSLog(@"%@",userLocation.location);
    
    _currentLocation = userLocation.location ;
    
}

#pragma mark -   mapView 回调 设置Annotation
-(MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
    
    /*
     目前学到两种 Annotation
     一种是用户定位的 蓝色圆圈  Annotation
     一种是查询显示的 紫色圆圈   Annotation
     */
    
    //判断是否是屏幕长按取得的目的地标注
    if (annotation == _destinationPoint)
    {
        static NSString *reuseIndetifier = @"startAnnotationReuseIndetifier";
        MAPinAnnotationView *annotationView = (MAPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
        if (annotationView == nil)
        {
            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
        }
        
        annotationView.canShowCallout = YES;
        
        // 下落效果
        annotationView.animatesDrop =  YES;
        
        return annotationView;
    }

    
    
    //判断是哪一种Annotation, 如果是标注,注释类型的Annotation则进入
    if([annotation isKindOfClass:[MAPointAnnotation class]])
    {
        //MAPinAnnotationView 的重用机制 类似于tableView
        static NSString *reuseIndetifier =@"annotationReuseIndetifier";
        //Annotation 视图
        CustomAnnotationView * annotationView = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
        if (annotationView ==nil) {
            annotationView = [[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
        }
        
        //自定义标记图片
        annotationView.image =[UIImage imageNamed:@"restaurant.png"];
        
        
        //弹出气泡
        annotationView.canShowCallout =NO;
        
        //默认情况下, 弹出的⽓气泡位于view正中上⽅方,可以设置calloutOffset改变view的位置,正
        //的偏移使view朝右下⽅方移动,负的朝左上⽅方,单位是像素
        annotationView.centerOffset =CGPointMake(0, -18);
        
        return annotationView;
    }
    return nil;
}


#pragma mark -   mapView 回调 覆盖物的回调方法. 这里用于设置路线
-(MAOverlayView *)mapView:(MAMapView *)mapView viewForOverlay:(id<MAOverlay>)overlay
{
    //如果是路线
    if ([overlay isKindOfClass:[MAPolyline class]])
    {
        NSLog(@"ssss");
        //创建路线视图
        MAPolylineView *polylineView = [[MAPolylineView alloc] initWithPolyline:overlay];
        //线宽
        polylineView.lineWidth =4;
        //线的颜色
        polylineView.strokeColor = [UIColor magentaColor];
        return polylineView;
    }
    return nil;
}


//地图上的标记被选中时执行逆地理编码
-(void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view
{
    //选中定位annotation的时候进行逆地里编码查询
    if ([view.annotation isKindOfClass:[MAUserLocation class]])
    {
        [self reGeoAction];
    }
}


//发起逆地理编码搜索请求
- (void)reGeoAction
{
    NSLog(@"333333333333");
    if(_currentLocation)
    {
        AMapReGeocodeSearchRequest *request = [[AMapReGeocodeSearchRequest alloc] init];
        request.location = [AMapGeoPoint locationWithLatitude:_currentLocation.coordinate.latitude longitude:_currentLocation.coordinate.longitude];
        [_search AMapReGoecodeSearch:request];
    }
}

//search出现错误时的回调
-(void)searchRequest:(id)request didFailWithError:(NSError *)error
{
    NSLog(@"request :%@ ,error :%@",request,error);
}

#pragma mark -   路线请求的回调
-(void)onNavigationSearchDone:(AMapNavigationSearchRequest *)request response:(AMapNavigationSearchResponse *)response
{
    //response.count>0 说明有可用的数据
    if (response.count >0)
    {
        
        //清空地图上Overlays的覆盖物, 这些覆盖物(这里指路线)存放在_pathPolyines
        [_mapView removeOverlays:_pathPolyines];
        //数组清空
        _pathPolyines = nil;
        
        //这里只显示一条路线
        //response.route.paths[0]  传入第一条路线给方法   route 路线的意思
        _pathPolyines = [self polylinesForPath:response.route.paths[0]];
        //[_pathPolyines retain];
        AMapPath *pathLength =response.route.paths[0];
        NSLog(@"%@",[NSString stringWithFormat:@"距离您当前位置 %ld 米",pathLength.distance]);
        _destinationPoint.title =[NSString stringWithFormat:@"距离您当前位置 %ld 米",pathLength.distance];
        [_mapView addOverlays:_pathPolyines];
        
        
        //调整地图显示范围
        //这个方法会把后面所列的annotation的数组里面涉及到的所有的annotation都显示出来,并且以一个最合理的方式来设置这个地图的显示范围
        [_mapView showAnnotations:@[_destinationPoint,_mapView.userLocation] animated:YES];
    }
}

#pragma mark - 路径解析方法  也就是解析 polylines 需要调用解析经纬度串

- (NSArray *)polylinesForPath:(AMapPath *)path
{
    if (path == nil || path.steps.count == 0)
    {
        return nil;
    }
    NSMutableArray *polylines = [NSMutableArray array];
    [path.steps enumerateObjectsUsingBlock:^(AMapStep *step, NSUInteger idx, BOOL *stop) {
        NSUInteger count = 0;
        //step.polyline 是一个字符串
        CLLocationCoordinate2D *coordinates = [self coordinatesForString:step.polyline
                                                         coordinateCount:&count
                                                              parseToken:@";"];
        
        //获得了一个 polyline串
        MAPolyline *polyline = [MAPolyline polylineWithCoordinates:coordinates count:count];
        [polylines addObject:polyline];
        free(coordinates), coordinates = NULL;
    }];
    return polylines;
}

#pragma mark - 解析经纬度串
- (CLLocationCoordinate2D *)coordinatesForString:(NSString *)string
                                 coordinateCount:(NSUInteger *)coordinateCount
                                      parseToken:(NSString *)token
{
    if (string == nil)
    {
        return NULL;
    }
    if (token == nil)
    {
        token = @",";
    }
    NSString *str = @"";
    if (![token isEqualToString:@","])
    {
        //字符串替换
        str = [string stringByReplacingOccurrencesOfString:token withString:@","];
    }
    else
    {
        str = [NSString stringWithString:string];
    }
    //分割字符串
    NSArray *components = [str componentsSeparatedByString:@","];
    NSUInteger count = [components count] / 2;
    if (coordinateCount != NULL)
    {
        *coordinateCount = count;
    }
    //创建坐标数组
    CLLocationCoordinate2D *coordinates = (CLLocationCoordinate2D*)malloc(count * sizeof(CLLocationCoordinate2D));
    //给坐标数组赋值
    for (int i = 0; i < count; i++)
    {
        coordinates[i].longitude = [[components objectAtIndex:2 * i]     doubleValue];
        coordinates[i].latitude  = [[components objectAtIndex:2 * i + 1] doubleValue];
    }
    return coordinates;
}



//search正确返回时的回调
-(void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response
{
    NSLog(@"4444444444444444");
    NSLog(@"response :%@",response);
    NSString *title =response.regeocode.addressComponent.city;
    if (title.length ==0) {
        title = response.regeocode.addressComponent.province;
    }
    //title为城市名
    _mapView.userLocation.title = title;
    NSLog(@"555555555555%@", title);
    //用户详细的格式化地址
    _mapView.userLocation.subtitle =response.regeocode.formattedAddress;
    
}


#pragma mark - search搜索正确返回时的回调
-(void)onPlaceSearchDone:(AMapPlaceSearchRequest *)request response:(AMapPlaceSearchResponse *)response
{
      NSLog(@"request :%@",request);
      NSLog(@"response:%@",response);
    if (response.pois.count >0)
    {
        //  response.pois  POI对象数组
        _pois = response.pois;
        
        [_tableView reloadData];
        
        //清空标注
        //在_mapView移除所有_annotations数组中的annotation, 这样用户定位的annotation不会被清除
        [_mapView removeAnnotations:_annotations];
        //清空数组
        [_annotations removeAllObjects];
        
        
    }
    
}

#pragma mark -- 模态返回
- (void)leftButtonAction
{
    // 把地图给移除
    [_mapView removeFromSuperview];
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonAction)];
    
    self.navigationItem.title = @"哞哞唱吧!";
    [self.navigationController.navigationBar setBarTintColor:COLOR(22, 88, 240, 1.0)];
    //调用MapView初始化方法
    [self initMapView];
    //调用search初始化 显示当前地址
    [self initSearch];
    //调用创建按钮
    [self initControls];
    //调用tableView 初始化
    [self initTableView];
    //调用数据初始化
    [self initAttributes];
    
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
